package com.applozic.mobicomkit.uiwidgets.conversation.view;

import android.content.Context;
import android.text.Spannable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.applozic.mobicomkit.api.conversation.Message;
import com.applozic.mobicommons.emoticon.EmojiconHandler;
import com.applozic.mobicommons.emoticon.EmoticonUtils;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.ui.component.BaseRelativeLayout;
import com.lottery.ruok.lottrey.userInfo.UserInfo;

import butterknife.BindView;
import de.hdodenhof.circleimageview.CircleImageView;
import glideHelp.GlideHelper;

public class CustomReceivedMessageView extends BaseRelativeLayout {
    @BindView(R.id.contactImage)
    CircleImageView circleImageView;
    @BindView(R.id.message_text)
    TextView message_text;
    @BindView(R.id.messageLayout)
    RelativeLayout messageLayout;

    public CustomReceivedMessageView(Context context) {
        super(context);
    }

    public CustomReceivedMessageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomReceivedMessageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(Context context, AttributeSet attrs, int defStyleAttr) {

    }

    @Override
    protected void initView(Context context) {
        setContentView(R.layout.custom_received_message_list_view);

        setRoundImg(circleImageView);
    }

    @Override
    protected void load(Context context) {

    }

    public void setData(Message message, EmojiconHandler emojiconHandler) {
        Spannable spannable = EmoticonUtils.getSmiledText(mContext, message.getMessage(), emojiconHandler);
        if (spannable.length() <= 300) {
            message_text.setText(spannable);
        }
    }

    private void setRoundImg(ImageView myAvatar) {
        if (myAvatar != null) {
            if (UserInfo.getToken().equals("")) {
                myAvatar.setImageResource(R.mipmap.chat_default);
            } else {
                if (UserInfo.getAvatar().equals("")) {
                    myAvatar.setImageResource(R.mipmap.chat_default);
                } else {
                    GlideHelper.loadRoundImage(getContext(), UserInfo.getAvatar(), myAvatar);
                }
            }
        }
    }

}
